﻿@using NC.Infrastructure.Domain.Identity
@using NC.Service
@using NC.Web.Models
@model List<NC.Infrastructure.Domain.Identity.Person>
@{
    ViewBag.Title = "Index";
}


<link href="~/Content/rippler/css/rippler.min.css" rel="stylesheet" />
<script src="~/Content/rippler/js/jquery.rippler.min.js"></script>
<section class="content-header">
    <h1>
        用户信息列表管理
    </h1>
    <ol class="breadcrumb">
        <li><a href=""><i class="fa fa-dashboard"></i>首页</a></li>
    </ol>
</section>
<section class="content">
    <div class="box box-primary">
        <div class="box-header with-border">
            <h3 class="box-title">用户信息列表信息</h3>
            <div class="row" style="margin-top: 20px;">
                <div class="col-md-4">
                    <div class="form-horizontal">
                        <div class="form-group">
                            <label class="col-md-2 control-label">身份</label>
                            <div class="col-md-10">
                                <select class="form-control" id="role" onchange="roleChange()" multiple="multiple">
                                    @{
                                        var roleDic = EnumDictionary.RoleDictionaryAll;
                                        int queryRole = Request.QueryString["role"] == null ? 0 : Convert.ToInt32(Request.QueryString["role"]);
                                        foreach (var role in roleDic)
                                        {
                                            if (role.Key == queryRole)
                                            {
                                    <option value="@role.Key" selected="selected">@role.Value</option>
                                            }
                                            else
                                            {
                                    <option value="@role.Key">@role.Value</option>
                                            }
                                        }
                                    }
                                </select>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-md-4">
                    <div class="form-horizontal">
                        <div class="form-group">
                            <label class="col-md-2 control-label">入学年份</label>
                            <div class="col-md-10">
                                <select class="form-control" id="InTime" onchange="TimeChange()">
                                    @{
                                        var timeDic = EnumDictionary.GetInSchoolTime;
                                        string queryInTime = Request.QueryString["time"] == null ? "-1" : Request.QueryString["time"];
                                        foreach (var time in timeDic)
                                        {
                                            if (time.Key == queryInTime)
                                            {
                                    <option value="@time.Key" selected="selected">@time.Value</option>
                                            }
                                            else
                                            {
                                    <option value="@time.Key">@time.Value</option>
                                            }
                                        }
                                    }
                                </select>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-md-4">
                    <div class="form-horizontal">
                        <div class="form-group">
                            <label class="col-md-2 control-label">审核状况</label>
                            <div class="col-md-10">
                                <select class="form-control" id="Audit" onchange="AuditChange()">
                                    @{
                                        var auditDic = EnumDictionary.AuditDictionaryAll;
                                        string queryAudit = Request.QueryString["audit"] == null ? "-1" : Request.QueryString["audit"];
                                        foreach (var audit in auditDic)
                                        {
                                            if (audit.Key == queryInTime)
                                            {
                                    <option value="@audit.Key" selected="selected">@audit.Value</option>
                                            }
                                            else
                                            {
                                    <option value="@audit.Key">@audit.Value</option>
                                            }
                                        }
                                    }
                                </select>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-md-4">
                    <div class="form-horizontal">
                        <div class="form-group">
                            <label class="col-md-2 control-label">搜索</label>
                            <div class="col-md-10">
                                <div class="input-group">
                                    <input type="text" class="form-control" id="search" />
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-info" onclick="search()">搜索</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-body no-padding">
            <div class="mailbox-controls">
                <!-- Check all button -->
                <button class="btn btn-default btn-sm checkbox-toggle" id="checkAll"><i class="glyphicon glyphicon-check"></i></button>
                <div class="btn-group">
                    <a href="@Url.Action("Create")" class="btn btn-default btn-sm"><i class="glyphicon glyphicon-plus"></i></a>
                    <button class="btn btn-default btn-sm" onclick="deleteData('@Url.Action("Delete")')"><i class="glyphicon glyphicon-trash"></i></button>
                    <button class="btn btn-default btn-sm" onclick="window.location.reload(true);"><i class="glyphicon glyphicon-refresh"></i></button>
                </div>
            </div>
            <div class="table-responsive mailbox-messages">
                <table class="table table-hover table-striped">
                    <thead>
                    <tr>
                        <th></th>
                        <th>用户名</th>
                        <th>头像</th>
                        <th>
                            真实姓名
                        </th>

                        <th>
                            身份
                        </th>

                        <th>
                            密码
                        </th>

                        <th>
                            学号
                        </th>

                        <th>
                            入学时间
                        </th>

                        <th>
                            个人简述
                        </th>

                        <th>
                            是否经过审核
                        </th>

                        <th>
                            操作
                        </th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach (var item in Model)
                    {
                        <tr>
                            <td>
                                <input type="checkbox" data-id="@item.Id"/>
                            </td>
                            <td>
                                @item.Name
                            </td>
                            <td>
                                <img style="border-radius: 50%; width: 40px; height: 40px;" src="@item.Image" alt="@item.Name" title="@item.Name"/>
                            </td>

                            <td>
                                @item.TickName
                            </td>

                            <td>
                                @EnumDictionary.RoleDictionary[(int) item.Role]
                            </td>

                            <td>
                                @item.Password
                            </td>

                            <td>
                                @item.SchoolNumber
                            </td>

                            <td>
                                @item.InSchoolTime.ToString()
                            </td>

                            <td>
                                @item.Description
                            </td>

                            <td>
                                @{
                                    string auditResult = "";
                                    if (item.Audit)
                                    {
                                        auditResult += "<label class='label label-success'>已审核</label>";
                                    }
                                    else
                                    {
                                        auditResult += "<label class='label label-primary'>未审核</label>";
                                    }
                                    @Html.Raw(auditResult)
                                    ;
                                }
                            </td>
                            <td>
                                <div class="btn-group">
                                    <div class="btn btn-default" onclick="deleteData('@Url.Action("Delete")', '@item.Id')">
                                        <i class="glyphicon glyphicon-trash"></i>
                                    </div>
                                    <a class="btn btn-default" href="@Url.Action("Details", new {id = item.Id})"><i class="glyphicon glyphicon-user"></i></a>
                                    <a class="btn btn-default" href="@Url.Action("Edit", new {id = item.Id})"><i class="glyphicon glyphicon-edit"></i></a>
                                </div>
                            </td>
                        </tr>
                    }
                    </tbody>
                </table>
                <div class="clearfix">
                    @{ int count = Convert.ToInt32(ViewBag.count);}
                    @Html.PageList(Url.Action("Index"), count)
                </div>
            </div>
        </div>
    </div>
</section>
<script src="~/Content/Assert/Js/Common.js"></script>
<script type="text/javascript">

    $("#role").select2();
    $(document).ready(function () {
        $("#search").onKeyDown(function (e) {
            if (e.keyCode == 13) {
                search();
            }
        });
    });

    function roleChange() {
        var roleId = $("#role").val();
        var url = setUrlValue("role", roleId);
        window.location.href = "@Url.Action("Index")" + url;
    }

    function TimeChange() {
        var time = $("#InTime").val();
        var url = setUrlValue("time", time);
        window.location.href = "@Url.Action("Index")" + url;
    }

    function AuditChange() {
        var audit = $("#Audit").val();
        var url = setUrlValue("audit", audit);
        window.location.href = "@Url.Action("Index")" + url;
    }

    function search() {
        var searchInfo = $("#search").val();
        var url = setUrlValue("search", searchInfo);
        window.location.href = "@Url.Action("Index")" + url;
    }
</script>
